package com.zhijian.wharf.controller.web;

import com.zhijian.response.annotation.Response;
import com.zhijian.util.page.Page;
import com.zhijian.wharf.annotation.LogOperation;
import com.zhijian.wharf.entity.vo.request.ApiLogSearchVo;
import com.zhijian.wharf.entity.vo.response.ApiLogStaByUserVo;
import com.zhijian.wharf.entity.vo.response.ApiLogStaVo;
import com.zhijian.wharf.entity.vo.response.ApiLogVo;
import com.zhijian.wharf.service.ApiLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
 * API日志 控制层
 *
 * @author auto
 * @version 1.0
 * @date 2024-06-17 19:08:34
 */
@Slf4j
@Controller
@Api(tags = "API日志")
public class ApiLogController {

    @Autowired
    private ApiLogService service;

    /**
     * 按照用户维度统计日志
     *
     * @return
     */
    @Response
    @GetMapping("/api/log/sta/user")
    @ApiOperation("按照用户维度统计日志")
    public List<ApiLogStaByUserVo> apiLogStaByUserVo() {
        return service.apiLogStaByUserVo();
    }

    /**
     * 统计
     *
     * @return
     */
    @Response
    @GetMapping("/api/log/sta")
    @ApiOperation("统计")
    public ApiLogStaVo sta() {
        return service.sta();
    }

    /**
     * 分页查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/api/log/page")
    @ApiOperation("分页查询")
    @LogOperation("web分页查询API日志")
    public Page<ApiLogVo> selectByCondition(@RequestBody(required = false) ApiLogSearchVo param) {
        if (param == null)
            param = ApiLogSearchVo.builder().build();
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return service.selectPage(param);
    }

}